from pathlib import Path

src_dir =Path('a')
dst_dir =Path('x')

def file_copy(fn1,fn2):
    with open (fn1, 'rb') as f1:
        with open (fn2, 'wb') as f2:
            length = 16 * 1024
            while True:
                buf = f1.read(length)
                if not buf:
                    break
                f2.write(buf)

def file_dir_copy(src_dir, dst_dir):
    items = src_dir.glob('**/*')
    for x in items:
        if x.is_dir():
            dst_dir = dst_dir / str(x)[-1]
            dst_dir.mkdir(parents=False, exist_ok=True)

        elif x.is_file():
            new_file = dst_dir / x.name
            new_file.touch()
            file_copy(str(x), str(new_file))

file_dir_copy(src_dir, dst_dir)

"""
源与目的不写死试下
"""
